/*
 * Copyright：fxsen <br/>
 * Date: 2022/1/19 19:10 <br/>
 * Email:fxsen@foxmail.com
 * Author: fxsen
 */
package com.fxsen.commons.sysmanager.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fxsen.commons.core.base.common.service.impl.CommonServiceImpl;
import com.fxsen.commons.sysmanager.core.entity.Permission;
import com.fxsen.commons.sysmanager.core.mapper.PermissionMapper;
import com.fxsen.commons.sysmanager.core.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @describe: 系统权限接口服务实现层
 * @date: 2022/1/19 19:10
 * @author: fxsen
 */
@Service
public class PermissionServiceImpl extends CommonServiceImpl<PermissionMapper,Permission> implements IPermissionService {
    @Autowired
    private PermissionMapper mapper;
    @Override
    public Set<String> permissionSet() {
        List<Permission> permissions = mapper.selectList(new QueryWrapper<>());
        Set<String> set = new HashSet<>();
        permissions.forEach(permission -> {
            set.add(permission.getTag());
        });
        return set;
    }

    @Override
    public List<Permission> selectList() {
        LambdaQueryWrapper<Permission> queryWrapper = new LambdaQueryWrapper<>();
        /*queryWrapper.eq(Permission :: getdelete_logic, BaseEntity.NO_DELETE);
        queryWrapper.eq(Permission :: getStatus,BaseEntity.STATUS_YES);
        queryWrapper.orderByAsc(Permission :: getSort);*/
        return mapper.selectList(queryWrapper);
    }

    @Override
    public List<Permission> findByPid(String pid) {
        return mapper.findByPid(pid);
    }

    @Override
    public Set<String> findPermissionTagByUserId(String userId) {
        return mapper.findPermissionTagByUserId(userId);
    }

    @Override
    public Permission findByTagAndUserId(String tag, String userId) {
        return mapper.findByTagAndUserId(tag,userId);
    }
}
